package com.homejoy.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.homejoy.common.annotation.Log;
import com.homejoy.common.core.controller.BaseController;
import com.homejoy.common.core.domain.AjaxResult;
import com.homejoy.common.enums.BusinessType;
import com.homejoy.system.domain.HomejoyPropertyPending;
import com.homejoy.system.service.IHomejoyPropertyPendingService;
import com.homejoy.common.utils.poi.ExcelUtil;
import com.homejoy.common.core.page.TableDataInfo;

/**
 * 待办管理Controller
 *
 * @author homeJoy
 * @date 2025-11-15
 */
@RestController
@RequestMapping("/system/pending")
public class HomejoyPropertyPendingController extends BaseController {
    @Autowired
    private IHomejoyPropertyPendingService homejoyPropertyPendingService;

    /**
     * 查询待办管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:pending:list')")
    @GetMapping("/list")
    public TableDataInfo list(HomejoyPropertyPending homejoyPropertyPending) {
        startPage();
        List<HomejoyPropertyPending> list = homejoyPropertyPendingService.selectHomejoyPropertyPendingList(homejoyPropertyPending);
        return getDataTable(list);
    }

    /**
     * 导出待办管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:pending:export')")
    @Log(title = "待办管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HomejoyPropertyPending homejoyPropertyPending) {
        List<HomejoyPropertyPending> list = homejoyPropertyPendingService.selectHomejoyPropertyPendingList(homejoyPropertyPending);
        ExcelUtil<HomejoyPropertyPending> util = new ExcelUtil<HomejoyPropertyPending>(HomejoyPropertyPending.class);
        util.exportExcel(response, list, "待办管理数据");
    }

    /**
     * 获取待办管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pending:query')")
    @GetMapping(value = "/{pendingId}")
    public AjaxResult getInfo(@PathVariable("pendingId") Long pendingId) {
        return success(homejoyPropertyPendingService.selectHomejoyPropertyPendingByPendingId(pendingId));
    }

    /**
     * 新增待办管理
     */
    @PreAuthorize("@ss.hasPermi('system:pending:add')")
    @Log(title = "待办管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HomejoyPropertyPending homejoyPropertyPending) {
        return toAjax(homejoyPropertyPendingService.insertHomejoyPropertyPending(homejoyPropertyPending));
    }

    /**
     * 修改待办管理
     */
    @PreAuthorize("@ss.hasPermi('system:pending:edit')")
    @Log(title = "待办管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HomejoyPropertyPending homejoyPropertyPending) {
        return toAjax(homejoyPropertyPendingService.updateHomejoyPropertyPending(homejoyPropertyPending));
    }

    /**
     * 删除待办管理
     */
    @PreAuthorize("@ss.hasPermi('system:pending:remove')")
    @Log(title = "待办管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{pendingIds}")
    public AjaxResult remove(@PathVariable Long[] pendingIds) {
        return toAjax(homejoyPropertyPendingService.deleteHomejoyPropertyPendingByPendingIds(pendingIds));
    }

    /**
     * 出租者点击同意
     * @param homejoyPropertyPending
     * @return
     */
    @RequestMapping("/landlordAgreed")
    public AjaxResult landlordAgreed(@RequestBody HomejoyPropertyPending homejoyPropertyPending) {
        return toAjax(homejoyPropertyPendingService.landlordAgreed(homejoyPropertyPending));
    }

    /**
     * 租用者点击同意
     * @param homejoyPropertyPending
     * @return
     */
    @RequestMapping("/tenantAgreed")
    public AjaxResult tenantAgreed(@RequestBody HomejoyPropertyPending homejoyPropertyPending) {
        return toAjax(homejoyPropertyPendingService.tenantAgreed(homejoyPropertyPending));
    }

}
